package com.haoyeteng.sxbd.modular.business.controller;

import com.haoyeteng.sxbd.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.haoyeteng.sxbd.core.base.model.ResponseResult;
import com.haoyeteng.sxbd.core.common.annotion.Permission;
import java.util.List;
import java.util.Map;
import com.haoyeteng.sxbd.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.haoyeteng.sxbd.modular.business.model.Machine;
import com.haoyeteng.sxbd.modular.business.service.IMachineService;

/**
 * 设备功能控制器
 *
 * @author haoyeteng
 * @Date 2019-05-26 18:02:22
 */
@Controller
@RequestMapping("/machine")
public class MachineController extends BaseController {

    private String PREFIX = "/business/machine/";

    @Autowired
    private IMachineService machineService;

    /**
     * 跳转到设备功能首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "machine.html";
    }

    /**
     * 跳转到添加设备功能
     */
    @RequestMapping("/machine_add")
    public String machineAdd() {
        return PREFIX + "machine_add.html";
    }

    /**
     * 跳转到修改设备功能
     */
    @RequestMapping("/machine_update/{machineId}")
    public String machineUpdate(@PathVariable Integer machineId, Model model) {
        Machine machine = machineService.selectById(machineId);
        model.addAttribute("item",machine);
        LogObjectHolder.me().set(machine);
        return PREFIX + "machine_edit.html";
    }

    /**
     * 获取设备功能列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    @Permission
    public ResponseResult<Object> list(String condition) {
    	ResponseResult<Object> result = new ResponseResult<Object>();
        result.setData(0);
 		result.setCount(0);
     	result.setCode(SUCCESS_TIP.getCode());
     	result.setMsg(SUCCESS_TIP.getMessage());
 		return result;
    }

    /**
     * 新增设备功能
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Permission
    public Object add(Machine machine) {
        machineService.insert(machine);
        return SUCCESS_TIP;
    }

    /**
     * 删除设备功能
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @Permission
    public Object delete(@RequestParam Integer machineId) {
        machineService.deleteById(machineId);
        return SUCCESS_TIP;
    }

    /**
     * 修改设备功能
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @Permission
    public Object update(Machine machine) {
        machineService.updateById(machine);
        return SUCCESS_TIP;
    }

    /**
     * 设备功能详情
     */
    @RequestMapping(value = "/detail/{machineId}")
    @ResponseBody
    public Object detail(@PathVariable("machineId") Integer machineId) {
        return machineService.selectById(machineId);
    }
}
